<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
//JHtml::stylesheet("https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css");
//JHtml::stylesheet(Juri::base() . 'components/com_cashbag/assets/js/bootstrap/css/bootstrap.css');
//JHtml::script("https://code.jquery.com/jquery-1.9.1.js");
//JHtml::script("https://code.jquery.com/ui/1.10.3/jquery-ui.js");
//JHtml::script(Juri::base() . 'components/com_cashbag/assets/js/jquery-ui-1.10.3/js/jquery-ui-1.10.3.custom.js');
//JHtml::script(Juri::base() . 'components/com_cashbag/assets/js/bootstrap/js/bootstrap.js');
JHtml::script(Juri::base() . 'components/com_cashbag/assets/js/bagAdmin.js');



 JToolBarHelper::title( JText::_( 'Products' ), 'generic.png' );
 /* JToolBarHelper::addNew();
 JToolBarHelper::editList();
  JToolBarHelper::publishList();
  JToolBarHelper::unpublishList();  
  JToolBarHelper::deleteList();  */
  JToolBarHelper::preferences('com_cashbag', '550');  
$style	='
';

?>
<div>
    <button id="bag_send_valid" class="ui-state-active ui-corner-all" >Enregistrer l'envoie d'un sac </button>&nbsp;&nbsp;
    <button id="details_casbag" class="ui-state-active ui-corner-all"> Afficher les détails du sac</button>
    <button id="edit_casbag" class="ui-state-active ui-corner-all"> Modifier la saisie d'un CASHBAG</button>
	<button id="send_proposition" class="ui-state-active ui-corner-all"> Envoyer la proposition au client</button>
    <a href="" id="last_demande" class="ui-state-highlight"> Afficher les demandes de sacs en attente</a>&nbsp;&nbsp;
    <a href="" id="last_send"> Afficher les sacs envoyés</a>
    
</div>
<br/><br/>
<form style="display: inline-block; width:100%;" action="index.php" method="post" name="adminForm" id="adminForm">
    <legend>Filtres</legend><br/><br/>
    <span >
        <label> Par le nom du client</label>  <input type="text" id="nom_client_bag" name="nom_client_bag"/>
        <label> Date de demande</label> <input type="text" id="date_demande_bag" name="demandedOn" />
        <label> Date d'expédition</label>  <input type="text" id="date_expedition_bag" name="receivedOn"/>
        <?php foreach ($this->cashFilter as $f){
                echo $f;
                }
        ?>
    </span>
    <input type="submit" id="filters_bag" value="Filtrer"/>
    <input type="hidden" name="option" value="com_cashbag"/>
    <input type="hidden" name="view" value="cashbag"/>

<br/><br/>
<table calss="ui-widget" width="100%">
    <tr style="text-align:center;" class="ui-widget-header">
        <th width="2px"></th>
        <th width="2%">
            #
        </th>
        <th>
            Nom du client
        </th>
        <th>
            Date de la demande
        </th>
        <th>
            Adresse de livraison
        </th>
        <th>
            Reférence interne
        </th>
        <th>
            Type de demande
        </th>
        <th>
            Expédié le
        </th>
        
        <th>
            Reçu le
        </th>
        <th>
            Nombre d'articles
        </th>
        <th>
            Accord du client
        </th>
    </tr>
    <?php
    $l= count($this->items);
    if($l>0){
        foreach ($this->items as $k=>$v){
                
                $hidden     = '';
                $nom        = $v->nom.'<br/>'.$v->prenom;
                $hidden     = '<input type="hidden" name="nom_'.$v->idb.'" value="'.$v->nom.'"/>';
                $hidden    .= '<input type="hidden" name="prenom_'.$v->idb.'" value="'.$v->prenom.'"/>';
                $demande    = $v->demande;
                $send       = $v->envoie;
                $received   = $v->reception;
                $type       = $v->type;
                $hidden    .= '<input type="hidden" name="type_'.$v->idb.'" value="'.$v->type.'"/>';
                $nbre       = $v->nbre_prod; 
                $ref_int    = $v->ref_interne;
                $hidden    .= '<input type="hidden" name="ref_'.$v->idb.'" value="'.$v->ref_interne.'"/>';
                $ad         = $v->adresse.'<br>'.$v->code_postale.'<br>'.$v->ville;
                $had        = str_replace('<br>', '+', $ad);
                $hidden    .= '<input type="hidden" name="addr_'.$v->idb.'" value="'.$had.'"/>';
                
                $idb        = $v->idb;
               // $ref_bag    = $v->bag_ref;
                $pub        = $v->published;
                switch ($pub) {
                    case '1':
                        $acc='<td>non traité</td>';
                        break;
                    case'2':
                        $acc='<td style="background: #F8DE6C;">en cours</td>';
                        break;
                    case'3':
                        $acc='<td style="background: #B9F86C;">OUI</td>';
                        break;
                    case'4':
                        $acc='<td style="background: #F88A6C;">NON</td>';
                        break;
                    default:
                        break;
                }
                
                $html ='<tr style="text-align:center;" class="ui-widget-content">
                        <td><input type="radio" id="'.$idb.'" name="cash_b"/></td><td>'.$idb.'</td>'
                     .'<td>'.$nom.'</td><td>'.$demande.'</td><td>'.$ad.'</td><td>'.$ref_int.'</td><td>'.$type.'</td><td>'.$send.'</td><td>'.$received.'</td>
                     <td>'.$nbre.'</td>'.$acc.'</tr>';
                echo $html;
                echo $hidden;
        }
    }else{
        echo '<tr><td colspan="10" style="text-align:center;"><h2>Aucun CASHBAG trouvé en base de données</h2></td></tr>';
    }
    ?>
</table>

<?php 
 
echo $this->pagination->getListFooter();
?>
<input type="hidden" name="option" value="com_cashbag" />
<!--input type="hidden" name="task" value="items" /-->
<input type="hidden" name="view" value="cashbag" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<script>
    initEvents();
</script>